﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="CreateUser.aspx.cs" Inherits="CreateUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
<%--    <script src="Scripts/jquery.min.js" type="text/javascript"> </script>--%>
    <link href="js/validationEngine.jquery.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery.validationEngine.js" type="text/javascript"></script>
    <script src="js/jquery.validationEngine-en.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <script  type="text/javascript">
        $(document).ready(function () {
            jQuery(".form").validationEngine({ scroll: false, focusFirstField: false });
        });

        function customValidate(field, rules, i, options) {
            var pattern = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
            var match = pattern.exec(field.val());
            if (field.val() == "") {
                return true;
            }
            else if (match == null) {
                return options.allrules.email.alertText;
            }
        }
    </script>
    <script>

        function CreateNewAccount() {
            //
            $('#createnewaccount').click(function () {
                if (!$(".form").validationEngine('validate')) {
                    return false;
                }
                $.ajax({
                    type: "POST",
                    url: "PIMService.asmx/CreateNewMember",
                    data: "{'_userName':'" + $("#create_username").val() + "','_password':'" + $("#create_password").val() + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        //alert(result.d);
                        if (result.d == 'NotOK' || result.d == '') {
                            alert('Create a new user is fail!');
                        }
                        else if (result.d == '10') {
                            alert('This username is already in system!');
                        }
                        else {
                            self.location = "Default.aspx"
                        }
                    },
                    error: function (result) {
                        alert('Can not create a new user!');
                    }
                });
                //                }
            });
        }

        $(document).ready(function () {
            CreateNewAccount();
        });
    </script>
    </script>
    <div id="content" class="clearfix">
        <div class="createuser clearfix" >
            <div class="bg01">
                <div class="bg02" >
                    <%--<div class="bg03 clearfix">--%>
                    <div class="bg03 clearfix" style="padding:20px;" >
                        <form method="post" action="#">
                        <div style="margin:0 auto ; width:400px;">
                        <div class="accountdiv">
                            <p style="text-align:center;font-size:16px;font-weight:bold">Sign up</p>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv">
                            <div class="text-field">
                            Email Address:
                            </div>
                            <div class="form-filed-account">
                                <input class="validate[required,funcCall[customValidate]] field-textbox1"  name="email" id="create_username" type="text" autocomplete="on" placeholder="Email address" />
                            </div>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv">
                            <div class="text-field">
                            Password:
                            </div >
                            <div class="form-filed-account">
                                <input class="validate[required,minSize[5],maxSize[50]] field-textbox1"  name="password" id="create_password" type="password" placeholder="Password" />
                            </div>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv">
                            <div class="text-field">
                            Confirm password:
                            </div>
                            <div class="form-filed-account">
                                <input class="validate[required,equals[create_password]] field-textbox1" name="confirmpassword" id="confirm_create_password" type="password" placeholder="Password">
                            </div>
                        </div>
                        <div style="clear:both"></div>
                        <div class="accountdiv" style="text-align:center;">
                            <input class="button-form"  id="createnewaccount" 
                                value="Sign up"  type="button"
                                 />
                        </div>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
